package com.softer.wxzj.controller;/**
 * @author Gong Zhiyang
 * @date 2019/5/29
 */

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseOwnerInfoMap;
import com.softer.wxzj.entity.SplitMerge;
import com.softer.wxzj.entity.SplitMergeReqList;
import com.softer.wxzj.service.SplitMergeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 拆分合并controller
 *
 * @author Gong Zhiyang
 * @date 2019/5/29
 */
@RequestMapping("/splitMerge")
@RestController
public class SplitMergeController {
    @Autowired
    private SplitMergeService splitMergeService;

    /**
     * 查询房屋合并/拆分审核列表
     *
     * @param page              分页信息
     * @param splitMergeReqList 查询实体
     *                          regionNo 小区编码
     *                          regionName 小区名称
     *                          createTime 申请开始时间
     *                          updateTime 申请结束时间
     *                          creater 申请人
     * @return 查询结果
     */
    @RequestMapping("/getSplitMergeAuditList")
    @LogRecord(description = "查询房屋合并/拆分审核列表", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.SELECT)
    public PageInfo<SplitMergeReqList> getSplitMergeAuditList(Page page, SplitMergeReqList splitMergeReqList) {
        return splitMergeService.getSplitMergeAuditList(page, splitMergeReqList);
    }

    /**
     * 查询房屋合并/拆分详情
     *
     * @param id req_list的Id
     * @return 查询结果
     */
    @RequestMapping("/getSplitMergeReqInfo")
    @LogRecord(description = "查询房屋合并/拆分详情", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.SELECT)
    public SplitMerge getSplitMergeReqInfo(String id) {
        return splitMergeService.getSplitMergeReqInfo(id);
    }

    /**
     * 房屋合并/拆分审核
     *
     * @param id      审核ID
     * @param opinion 审批意见
     * @param mark    审批通过 audit_pass
     *                审批否决 audit_veto
     *                审批退回 audit_back
     * @return 操作结果
     */
    @RequestMapping("/audit")
    @LogRecord(description = "房屋合并/拆分审核", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.UPDATE)
    public CommonResult audit(String id, String opinion, String mark) {
        return splitMergeService.audit(id, opinion, mark);
    }

    /**
     * 房屋合并/拆分审变更查询列表
     *
     * @param page              分页信息
     * @param splitMergeReqList 查询实体
     *                          regionNo 小区编码
     *                          regionName 小区名称
     *                          createTime 申请开始时间
     *                          updateTime 申请结束时间
     *                          creater 申请人
     * @return 查询结果
     */
    @RequestMapping("/getSplitMergeList")
    @LogRecord(description = "房屋合并/拆分变更查询列表", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.SELECT)
    public PageInfo<SplitMergeReqList> getSplitMergeList(Page page, SplitMergeReqList splitMergeReqList) {
        return splitMergeService.getSplitMergeList(page, splitMergeReqList);
    }

    /**
     * 房屋合并/拆分
     *
     * @param splitMerge 拆分/合并实体
     * @return 合并/拆分结果
     */
    @RequestMapping("/splitMerge")
    @LogRecord(description = "房屋合并/拆分", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.UPDATE)
    public CommonResult splitMerge(@RequestBody SplitMerge splitMerge) {
        return splitMergeService.splitMerge(splitMerge);
    }

    /**
     * 模糊查询房屋合并/拆分审变更查询列表
     *
     * @param page  分页信息
     * @param param 模糊查询参数
     * @return 查询结果
     */
    @RequestMapping("/getSplitMergeListFuzzy")
    @LogRecord(description = "模糊查询房屋合并/拆分变更查询列表", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.SELECT)
    public PageInfo<SplitMergeReqList> getSplitMergeListFuzzy(Page page, String param) {
        return splitMergeService.getSplitMergeAuditListFuzzy(page, param);
    }

    /**
     * 拆分前查询房屋详情
     *
     * @param id 房屋Id
     * @return 详情信息
     */
    @RequestMapping("/getSplitInfo")
    @LogRecord(description = "拆分前查询房屋详情", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.SELECT)
    public BaseOwnerInfoMap getSplitInfo(String id) {
        return splitMergeService.getSplitInfo(id);
    }


    /**
     * 合并前查询房屋详情
     *
     * @param id 合并前房屋ID集合，以“，”分隔
     * @return 详情信息
     */
    @RequestMapping("/getMergeInfo")
    @LogRecord(description = "合并前查询房屋详情", operationUnit = LogOperationUnit.SPLIT_MERGE, operationType = LogOperationType.SELECT)
    public List<BaseOwnerInfoMap> getMergeInfo(String id) {
        return splitMergeService.getMergeInfo(id);
    }

    /**
     * 校验房间是否存在在途业务
     *
     * @param houseId 房间ID
     * @return 业务信息，无在途业务，返回null
     */
    @PostMapping("/checkHouseInTrain")
    public String checkHouseInTrain(String houseId) {
        return splitMergeService.checkHouseInTrain(houseId);
    }
}
